#import <Foundation/Foundation.h>

// Utworzenie obiektu cakowitoliczbowego
#define INTOBJ(v) [NSNumber numberWithInteger: v]

// Dodanie metody print do klasy NSSet przy uyciu kategorii o nazwie Printing

@interface NSSet (Printing)
-(void) print;
@end

@implementation NSSet (Printing)
-(void) print {
    printf ("{");

    for (NSNumber *element in self)
        printf (" %li ", (long) [element integerValue]);

    printf ("}\n");
}
@end

int main (int argc, char *argv[])
{
    NSAutoreleasePool  * pool = [[NSAutoreleasePool alloc] init];

    NSMutableSet *set1 = [NSMutableSet setWithObjects:
          INTOBJ(1), INTOBJ(3), INTOBJ(5), INTOBJ(10), nil];
    NSSet *set2 = [NSSet setWithObjects:
          INTOBJ(-5), INTOBJ(100), INTOBJ(3), INTOBJ(5), nil];
    NSSet *set3 = [NSSet setWithObjects:
          INTOBJ(12), INTOBJ(200), INTOBJ(3), nil];

    NSLog (@"set1: ");
    [set1 print];
    NSLog (@"set2: ");
    [set2 print];

    // Porwnywanie
    if ([set1 isEqualToSet: set2] == YES)
        NSLog (@"Zbir set1 jest rwny zbiorowi set2");
    else
        NSLog (@"Zbir set1 nie jest rwny zbiorowi set2");

    // Sprawdzanie istnienia elementw

    if ([set1 containsObject: INTOBJ(10)] == YES)
        NSLog (@"Zbir set1 zawiera 10");
    else
        NSLog (@"Zbir set1 nie zawiera 10");

    if ([set2 containsObject: INTOBJ(10)] == YES)
        NSLog (@"Zbir set2 zawiera 10");
    else
        NSLog (@"Zbir set2 nie zawiera 10");

    // Dodanie i usunicie obiektw ze zmiennego zbioru set1

    [set1 addObject: INTOBJ(4)];
    [set1 removeObject: INTOBJ(10)];
    NSLog (@"Zbir set1 po dodaniu 4 i usuniciu 10: ");
    [set1 print];

    // Obliczenie czci wsplnej dwch zbiorw

    [set1 intersectSet: set2];
    NSLog (@"Cz wsplna zbiorw set1 i set2: ");
    [set1 print];

    // Suma zbiorw

    [set1 unionSet:set3];
    NSLog (@"Suma zbiorw set1 i set3: ");
    [set1 print];

    [pool drain];
    return 0;
}